<?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Administrator Memo Ajax View
***********************************************************/
?>

<?php include_once "../../model/AdministratorModel.php"; ?>
<?php include_once "../../model/SessionModel.php"; ?>
<?php session_start(); ?>

<?php
if($_SESSION['session']->currentConnection->type == "MYSQL"){
?>
<div class="section_title" id="memo"><h1> Moteurs de la base </h1></div>
<div class="section_info">
	Obtention des informations propres au moteurs de la base de donnée. 
</div>

<div class="article">

	<?php
	if(isset($_SESSION['session']->userLogin)){

	?>
	<div class="section_title_small_blue"><h4>Taille de la SGA</h4></div>
	
	<div class="tableContainer" >
		<table class="tableQueryCenter">
			<tr>
				<th>Nom</th>
				<th>Commentaire</th>
				<th>Transactions</th>
				<th>Point de sauvegarde</th>
			</tr>
		<?php
		$nbrow = AdministratorModel::getEngines($_SESSION['session']->currentConnection, $result);
			foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['ENGINE']."</td>\n";
				echo "<td>".$row['COMMENT']."</td>\n";
				echo "<td>".$row['TRANSACTIONS']."</td>\n";
				echo "<td>".$row['SAVEPOINTS']."</td>\n";
				echo"</tr>";
			}
		}
		?>
		</table>
	</div>
	<!--<div id="chart_bytes" class="chart"></div>-->
</div>

<?php
}
else if($_SESSION['session']->currentConnection->type == "ORACLE"){
?>
<div class="section_title" id="memo"><h1> Occupation Mémoire </h1></div>
<div class="section_info">
	Obtention des informations propres à l'occupation mémoire. 
</div>

<div class="article">

	<?php
	if(isset($_SESSION['session']->userLogin)){

	?>
	<div class="section_title_small_blue"><h4>Taille de la SGA</h4></div>
	
	<div class="tableContainer" >
		<table class="tableQueryCenter">
			<tr>
				<th>Nom</th>
				<th>Valeur(en MO)</th>
			</tr>
		<?php
		$nbrow = AdministratorModel::getSGASize($_SESSION['session']->currentConnection, $result);
			foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['NAME']."</td>\n";
				echo "<td>".(number_format(($row['VALUE']/1048576),2))."</td>\n";
				echo"</tr>";
			}
		?>
		</table>
	</div>
	
	<div class="section_title_small_blue"><h4>Espace libre de la SGA</h4></div>

	<div class="tableContainer" >
		<table class="tableQueryCenter">
			<tr>
				<th>POOL</th>
				<th>Mémoire libre(en MO)</th>
			</tr>
		<?php
		$nbrow = AdministratorModel::getSGAFreeMemory($_SESSION['session']->currentConnection, $result);
			foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['POOL']."</td>\n";
				echo "<td>".$row['FREE_MEMORY_IN_MO']."</td>\n";
				echo"</tr>";
			}
		}
		?>
		</table>
	</div>

	<!--<div id="chart_bytes" class="chart"></div>-->
</div>
<?php
}
?>

<script type="text/javascript">
	
	/*
	function drawCharts() {
		drawMemoryChart();
	}
	
	function drawMemoryChart() {
	var bytes = <?php echo $bytesUsed; ?> ; 
	var freebytes = <?php echo ($bytesMax - $bytesUsed); ?> ; 
	
	
	var data = google.visualization.arrayToDataTable([
			['Type', 'Amount'],
			['Used', bytes],
			['Free', freebytes]
		]);

		var options = {
			title: 'Memory Usage',
			backgroundColor:{
				fill: '#FAFAFA'
			},
			width: 400,
			height:200
		};

		var chart = new google.visualization.PieChart(document.getElementById('chart_bytes'));
		chart.draw(data, options);
	}

	drawCharts();
	*/
</script>